package me.shurufa.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import me.shurufa.R;
import me.shurufa.fragments.BookCommentFragment;
import me.shurufa.utils.Constants;

/**
 * 作者 : andy
 * 日期 : 16/3/13 21:22
 * 邮箱 : andyxialm@gmail.com
 * 描述 : 消息通知 书摘详情界面
 */
public class NoticeBookCommentInfoActivity extends BaseActivity {

    private static final String ARGUMENTS_BOOKNAME = "BOOKNAME";
    private static final String ARGUMENTS_ID = "ID";

    private String mBookname;
    private long mId;
    private int mWhereFrom;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        activity_layout_res = R.layout.activity_message;
        super.onCreate(savedInstanceState);
        parseArgumetns();
        initView();
        initFragment();
    }

    /**
     * 初始化参数
     * @param in
     * @param bookname
     * @param id
     * @param fromWhere
     */
    public static void initArguments(Intent in, String bookname, long id, int fromWhere) {
        in.putExtra(ARGUMENTS_BOOKNAME, bookname);
        in.putExtra(ARGUMENTS_ID, id);
        in.putExtra(Constants.ARG_FROM_WHERE, fromWhere);
    }

    /**
     * 解析参数
     */
    private void parseArgumetns() {
        if (null != getIntent()) {
            mBookname = getIntent().getStringExtra(ARGUMENTS_BOOKNAME);
            mId = getIntent().getLongExtra(ARGUMENTS_ID, 0);
            mWhereFrom = getIntent().getIntExtra(Constants.ARG_FROM_WHERE, 0);
        }
    }

    private void initView() {
        titleTextView.setText(mBookname);
    }

    private void initFragment() {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.fragment_container, BookCommentFragment.newInstance(mId, mBookname, mWhereFrom, ""));
        ft.commit();
    }
}
